package com.example.basemvvmkotlin.ui

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.example.basemvvmkotlin.R
import com.example.basemvvmkotlin.fragment.TestRvFragment

class FragmentRvActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_fragment_rv)
        replaceFragment(TestRvFragment())
    }

     private fun replaceFragment(fragment: Fragment) {
        val fragmentManager: FragmentManager = supportFragmentManager
        val transaction: FragmentTransaction = fragmentManager.beginTransaction() // 开启一个事务
        transaction.replace(R.id.sub_view, fragment)
        transaction.commit()
    }

}